#include "loginwidget.h"
#include "ui_loginwidget.h"
#include "controlwidget.h"

LoginWidget::LoginWidget(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::LoginWidget)
{
    ui->setupUi(this);
    //调整窗口大小
    this->resize(500,400);
    this->setMaximumSize(450,300);
    this->setMinimumSize(450,300);


    //窗口属性
    this->setWindowTitle(QString("智能家居"));
    QIcon windowIcon = QIcon(QPixmap(QString(":/new/prefix1/images/窗口.png")));
    this->setWindowIcon(windowIcon);

    //背景图片
    QPalette pal;
    pal.setBrush(QPalette::Background,\
                 QBrush(QPixmap(QString(":/new/prefix1/images/loginbg.png")).scaled(500,450)));
    this->setPalette(pal);
    //头像
    label = new QLabel();
    label->resize(50,50);
    label->setPixmap(QPixmap(QString(":/new/prefix1/images/头像.png")).scaled(60,60));
    labelLayout = new QHBoxLayout();
    labelLayout->setContentsMargins(0,0,0,0);
    labelLayout->addStretch();
    labelLayout->addWidget(label);
    labelLayout->addStretch();

    //字体
    QFont font;
    font.setPixelSize(15);
    font.setBold(true);

    //用户名
    nameLineEdit = new QLineEdit();
    nameLineEdit->setPlaceholderText(QString("账号"));
    nameLineEdit->setFont(font);
    //密码
    passwordLineEdit = new QLineEdit();
    passwordLineEdit->setPlaceholderText(QString("密码"));
    passwordLineEdit->setFont(font);
    passwordLineEdit->setEchoMode(QLineEdit::Password);

    //登录
    loginBtn = new QPushButton(QString("登录"));
    loginBtn->setFont(font);
    //注册
    registBtn = new QPushButton(QString("注册"));
//    registBtn->setGeometry(8,270,80,30);
//    registBtn->setFlat();
    registBtn->setFont(font);

    checkBoxLayout = new QHBoxLayout;
    checkBoxLayout->addWidget(loginBtn);
    checkBoxLayout->addWidget(registBtn);



    mainLayout = new QVBoxLayout();
    mainLayout->setContentsMargins(80,20,80,50);
    mainLayout->addLayout(labelLayout);
    mainLayout->addWidget(nameLineEdit);
    mainLayout->addWidget(passwordLineEdit);
    mainLayout->addLayout(checkBoxLayout);

    this->setLayout(mainLayout);
    //链接信号与槽
    connect(loginBtn,SIGNAL(clicked(bool)),this,SLOT(loginBtnSlot()));

}

LoginWidget::~LoginWidget()
{
    delete ui;
}

void LoginWidget::loginBtnSlot()
{
    this->close();
    controlWidget *r = new controlWidget();
    r->show();
}




